package zelix.gui.clickguis.kendall.components.impls;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import zelix.gui.clickguis.N3ro.Utils.RenderUtil;
import zelix.gui.clickguis.kendall.components.Component;
import zelix.utils.hooks.visual.ColorUtils;
import zelix.utils.hooks.visual.RenderUtils;
import zelix.utils.hooks.visual.font.FontLoaders;
import zelix.value.NumberValue;

public class KendallSIlder extends Component {
    public NumberValue value;
    public KendallButton parent;
    public float x;
    public float y;
    public double moveSSL;
    public int per = 0;
    public KendallSIlder(NumberValue value,KendallButton parent){
        this.value = value;
        this.parent = parent;
    }
    @Override
    public void render(float x,float y,int mouseX, int mouseY){




        RenderUtils.drawBorderedRect(x,y,x+500/2,y+58/2,0,0,0xFF1F2022);
        FontLoaders.default14.drawString(this.value.getRenderName(),x+20/2f,y+5,0x99F5F5F7);
        FontLoaders.default14.drawString(this.value.getValue().toString(),x+240-FontLoaders.default14.getStringWidth(this.value.getValue().toString()),y+5,0x99F5F5F7);
        RenderUtils.drawRoundRect(x+20/2f,y+15,x+20/2f + 230,y+20,2,0xFF181818);
        float range = this.value.getMax().floatValue() - this.value.getMin().floatValue();
        float precent = range/100f;
        per = (int)((this.value.getValue().floatValue() - this.value.getMin().floatValue())/precent);

        GL11.glEnable(GL11.GL_MULT);
        GL11.glEnable(GL11.GL_BLEND);

        RenderUtil.drawRoundRect(x+20/2f,y+15,x+20/2f + 2.3*per,y+20,1,2,0XFFF5F5F7);
        RenderUtil.drawRoundRect(x+20/2f + 2.3*per-3,y+11,x+20/2f + 2.3*per+3,y+24,0,1, 0XFFF5F5F7);

        GL11.glDisable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_MULT);

        if (KendallButton.isButtonHovered(x+20/2f,y+11, x+20/2f + 240,y+24,mouseX,mouseY) && Mouse.isButtonDown((int)0)) {
            double inc = 0.01;
            double valAbs = (double) mouseX - ((double) x+20/2f + 1.0D);
            double perc = valAbs / 230.0D;
            perc = Math.min(Math.max(0.0D, perc), 1.0D);
            double valRel = (this.value.getMax() - this.value.getMin()) * perc;
            double val = this.value.getMin() + valRel;
            val = (double) Math.round(val * (1.0D / inc)) / (1.0D / inc);
            value.setValue(val);
        }
        //ni shi zui xing de CX ban me?额？
    }

}
